module Language.Coal.Util where

import Control.Monad.State

mapSnd :: (a -> b) -> [(c, a)] -> [(c, b)]
mapSnd f l = map (\(c, a) -> (c, f a)) l

mapFst :: (a -> b) -> [(a, c)] -> [(b, c)]
mapFst f l = map (\(a, c) -> (f a, c)) l

fromJust (Just a) = a

notModify :: Monad m => StateT a m b -> StateT a m b
notModify = notModifyWith id

notModifyWith :: Monad m => (a -> a) -> StateT a m b -> StateT a m b
notModifyWith f s = do 
		ca <- get
		modify f
		res <- s
		put ca
		return res